/*相似主题加载及评论内容实现*/
var tmRelation = {
	timer:null,
	mark:true,
	load:function(){
		var typeId = $("body").data("typeid");
		var filterId = $("body").data("filterid");
		var params = {"typeId":typeId,"filterId":filterId};
		$.ajax({
			type:"post",
			url:basePath+"/blog/relation.do",
			data:params,
			success:function(data){
				var html ="",len = data.length;
				if(data&& len>0){
					for(var i=0;i<len;i++){
						html+= "<li><a href='"+basePath+"/blog/detail/"+data[i].id+".do"+"'><img src='"+basePath+"/"+data[i].img+"' alt='' /></a></li>";
					}
					for(var j=0;j<4-len;j++){
						html+= "<li><a href=''><img src='"+basePath+"/resources/images/noimage.gif' alt='' /></a></li>";
					}
					$("#relationbox").html(html);
				}else{
					$(".relation").remove();
				}
			}
		});
	},
	saveComment:function(){
		var content = $("#content").val();
		var blogId = $("body").data("filterid");
		var type = $("body").data("type");
		var params = {"content":content,"blogId":blogId,type:type};
		var username = $("#username").text();
		//清空并且获取焦点
		$("#content").val("").focus();
		if(isEmpty(username)){
			tmLogin.login();
			return;
		}
		if((isEmpty(content)) || (content.length<4)){
			tzMessage.tip("你好坏！评论内容至少4个字符...");
			return;
		}
		$.ajax({
			type:"post",
			url:basePath+"/comment/save.do",
			data:params,
			success:function(data){
				$(".commentbox").prepend("<div class='comment' data-opid='"+data.id+"'>"+
				"	<ul class='links inline'>"+
				"	<li class='comment-reply first last'><a href='javascript:void(0);' data-opid='"+data.id+"'>回复</a></li>"+
				"	</ul>"+
				"	<div class='submitted'> <span rel='sioc:has_creator'><a href='#' title='查看用户资料' class='username' >"+username+"</a></span> <span class='marker'>老师</span> </div>"+
				"	<div class='content'>"+
				"	<span rel='sioc:reply_of' class='rdf-meta element-hidden'></span> "+content+
				"	<p class='submitted'><span>刚刚</span></p>"+
				"	</div>"+
				"	</div>");
			}
		});
	},
	loadComment:function(type){
		clearTimeout(this.timer);
		this.timer = setTimeout(function(){
			var blogId = $("body").data("filterid");
			$.ajax({
				type:"post",
				url:basePath+"/comment/find.do",
				data:{blogId:blogId,type:type},
				success:function(dataArr){
					var len = dataArr.length;
					if(len){
						var html = "";
						for(var i=0;i<len;i++){
							var data = dataArr[i];
							html+="<div class='comment' data-opid='"+data.id+"'>"+
							"	<ul class='links inline'>"+
							"	<li class='comment-reply first last'><a href='javascript:void(0);' data-opid='"+data.id+"'>回复</a></li>"+
							"	</ul>"+
							"	<div class='submitted'> <span rel='sioc:has_creator'><a href='#' title='查看用户资料' class='username' >"+data.username+"</a></span> <span class='marker'>老师</span> </div>"+
							"	<div class='content'>"+
							"	<span rel='sioc:reply_of' class='rdf-meta element-hidden'></span> "+data.content+
							"	<p class='submitted'><span>"+data.createTime+"</span></p>"+
							"	</div>"+
							"	</div>";
						}
						$(".commentbox").append(html);
					}else{
						
					}
				}
			});
		});
	}
};